<?php
require_once('EmsModelObject.php');
require_once('Location.php');
require_once('User.php');
/**
 * Description of Ticket
 *
 * @author sebastian
 */
class Ticket extends EmsModelObject
{
    
    //Properties
    
    private $ticketCode;
    public function TicketCode($value)
    {
        if($value == NULL)
            return $this->ticketCode;
        $this->ticketCode = value;
    }
    
    private $seat;
    public function Seat($value)
    {
        if($value == NULL)
            return $this->seat;
        
        if(!is_int($value))
        	throw new Exception("Ticket->Seat has to be int");
        if($value < 0)
        	throw new Exception("Ticket->Seat has to be greater or equal 0");
        
        $this->seat = $value;
    }
    
    private $row;
    public function Row($value)
    {
        if($value == NULL)
            return $this->row;
        
        if(!is_int($value))
        throw new Exception("Ticket->Row has to be int");
        if($value < 0)
        throw new Exception("Ticket->Row has to be greater or equal 0");
        
        $this->row = $value;
    }
   
        
    //Date (Event show)
    private $date;
    public function Date($value)
    {
        if($value == NULL)
            return $this->date;
        $this->date = $value;        
                
    }
    
    //Time(Event show)
    private $time;
    public function Time($value)
    {
        if($value == NULL)
            return $this->time;
        $this->time = $value;        
                
    }
    
    //Location
    private $location;
    public function Location($value)
    {
        if($value == NULL)
            return $this->location;
        
        if(!($value instanceof Location))
        	throw new Exception("Value is not an instance of Location. Type is ".gettype($value));
        
        $this->location = $value;        
                
    }
    
    //Event
    private $event;
    public function Event($value)
    {
        if($value == NULL)
            return $this->event;
        $this->event = $value;        
                
    }
    
    //Price
    private $price;
    public function Price($value)
    {
        if($value == NULL)
            return $this->price;
        
        if(!is_int($value))
        	throw new Exception("Ticket->Price has to be int");
        if($value < 0)
        	throw new Exception("Ticket->Price has to be greater or equal 0");
        
        $this->price = $value;
    }
    
    //PriceCategory
    private $priceCategy;
    public function PriceCategory($value)
    {
        if($value == NULL)
            return $this->priceCategy;
        $this->priceCategy = $value;        
                
    }
    //Status
    private $status;
    public function Status($value)
    {
        if($value == NULL)
            return $this->status;
        $this->status = $value;        
                
    }
    //Owner
    private $ticketOwner;
    public function TicketOwner($value)
    {
        if($value == NULL)
            return $this->ticketOwner;
        
        if(!($value instanceof User))
        	throw new Exception("Value is not an instance of User. Type is ".gettype($value));
        
        //User validieren...
        $this->ticketOwner = $value;        
                
    }
    
   //Constructor
   public function __construct($entity)
   {
   		//$this->SetId($entity->idLocation);
       //Map Entity to Object
   }

   public function IsValid()
   {
		$isValid = true;
   		//All Properties are mendatory. 
   		//Loop through and check for NULL. If NULL -> add name to property error list
   		foreach($this as $var => $value) 
   		{
   			if(!isset($value))
			{
				$isValid = false;
   				$this->AddPropertyError($var);
			}
   		}
		return $isValid;
   }
   
   public function SaveChanges()
   {
   		//Save changes to DB...
   }
   
    //Methods
    public function BookTicket($username)
    {
        //Check username and privileges and book ticket
    }
    
    public function ReleaseTicket($username)
    {
        //Check username, owner and privilegen and release Ticket
    }
    
    
    public static function GetType()
    {
    	return __CLASS__;
    }
}

?>
